import sys
import json
import pywbem

# SMI-S 服务器信息
SMIS_HOST = sys.argv[1]
SMIS_USER = sys.argv[2]
SMIS_PASS = sys.argv[3]
SMIS_NAMESPACE = sys.argv[4]

# 连接 SMI-S 服务器
conn = pywbem.WBEMConnection(SMIS_HOST, (SMIS_USER, SMIS_PASS),default_namespace=SMIS_NAMESPACE,timeout=30, no_verification=True)

def get_fan_info():
    dict_item=[]
    try:
        instances = conn.EnumerateInstances("CIM_Fan", namespace=SMIS_NAMESPACE)
        print(instances)
        for inst in instances:
            print(inst)
            name = inst.get("ElementName", "Unknown")
            speed = inst.get("DesiredSpeed", "Unknown")
            status = inst.get("OperationalStatus", [])
            print(f"🌀 风扇: {name}, 转速: {speed} RPM, 状态: {status}")
            dict_item.append({"name": name})
        print(json.dumps(dict_item))
    except Exception as e:
        print(f"获取内存使用率失败: {e}")

if __name__ == "__main__":
    get_fan_info()
    conn.close()